<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* 属性选择器 */
        [name=username] {
            color: red;
        }
    </style>
</head>

<body>
    <input type="text" value="worry" name="username">
    <input type="text" value="worry123" name="password"> 
    <button>登录</button>
</body>

</html>
<script src="./axios.js"></script>
<script>
    var oTxt1 = document.querySelector("[name=username]")
    var oTxt2 = document.querySelector("[name=password]") 
    var oBtn = document.querySelector("button")
    //   点击的时候发起请求
    oBtn.onclick = function () {
        axios({
            method:"post",
            url:"http://localhost:8888/users/login",
            headers:{
                "content-type":"application/x-www-form-urlencoded"
            },
            data:{
                username:oTxt1.value,
                password:oTxt2.value, 
            }
        }).then(res => {
            // console.log(res.data.code);
            if (res.data.code!=1) {
                alert("登录失败")
               location.href='register.html'
            }

            // 成功
            location.href = 'list.html';// 跳转到list页
        })
    }

</script>